﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COP.Objects.Config;
using COP.Readers;
using System.Collections;
using COP.Extractors;
using COP.Objects.Maps;

namespace ClientApp
{
    public class CustomMAP : MAP
    {

        public override void Append(object data)
        {
            string[] dataArr = data.ToString().Split('=');
            this.key = dataArr[0];
            this.value = dataArr[1];
        }
    }

    public class MyExtractor : IExtractor
    {
        public IEnumerable ExtractSource(IEnumerable sourceData)
        {
            return new string[] { "A=1", "B=2", "C=3" };
        }

        public string ExtractKey(object valNode, bool IsKeyMandate)
        {
            return "Data";

        }
    }

    public class CustomReader : IConfigReader
    {
        public IList<ConfigBase> Read()
        {
            IList<ConfigBase> configlist = new List<ConfigBase>();
            for (int counter = 0; counter < 10; counter++)
            {
                ConfigBase c = new BooleanConfig(null);
                configlist.Add(c);
            }
            return configlist;

        }

        public ConfigBase ReadTag(string name)
        {
            return ReadNode("(MultiList=Data[A=1,B=2,C=3])");
        }

        private ConfigBase ReadNode(IEnumerable node)
        {
            ConfigBase config = new ManyToManyConfig(new MyExtractor());
            config.SetMAPToCreate(new CustomMAP());
            config.Create(node);
            return config;
        }

    }

}